package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbSpecificationOptionMapper;
import com.bw1806.pojo.TbSpecificationOption;
import com.bw1806.pojo.TbSpecificationOptionExample;
import com.bw1806.sellergoods.service.TbSpecificationOptionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbSpecificationOptionServiceImpl implements TbSpecificationOptionService {

    @Autowired
    private TbSpecificationOptionMapper tbSpecificationOptionMapper;

    @Override
    public List<TbSpecificationOption> findAll() {
        return tbSpecificationOptionMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbSpecificationOption> pagelist(TbSpecificationOption tbSpecificationOption,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbSpecificationOptionExample example=new TbSpecificationOptionExample();

        TbSpecificationOptionExample.Criteria criteria = example.createCriteria();

        if(tbSpecificationOption!=null){
            //if(tbSpecificationOption.getName()!=null && tbSpecificationOption.getName().length()>0){
            //    criteria.andNameLike("%"+tbSpecificationOption.getName()+"%");
           // }
        }

        Page<TbSpecificationOption> page= (Page<TbSpecificationOption>) tbSpecificationOptionMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbSpecificationOption tbSpecificationOption) {
        Long id = tbSpecificationOption.getId();
        if(id != null && id !=0){
            tbSpecificationOptionMapper.updateByPrimaryKey(tbSpecificationOption);
        } else{
            tbSpecificationOptionMapper.insert(tbSpecificationOption);
        }
    }

    @Override
    public TbSpecificationOption getById(Long id) {
        return tbSpecificationOptionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbSpecificationOptionMapper.deleteByPrimaryKey(id);
        }
        //tbSpecificationOptionMapper.deletebth(ids);
    }
}
